package ycl.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ycl.common.result.REnum;
import ycl.common.result.Result;
import ycl.common.base.controller.BaseController;
import ycl.common.models.base.A;
import ycl.system.entity.SysMenu;
import ycl.system.req.SysMenuReq;
import ycl.system.res.SysMenuRes;
import ycl.system.service.SysMenuService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 菜单 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-03-03 11:43:56
 */
@RestController
@RequestMapping("/sys-menu")
@Api(tags = "菜单")
public class SysMenuController extends BaseController<SysMenu, SysMenuReq, SysMenuRes> {

	@Resource
	private SysMenuService sysMenuService;

	@Override
	@Operation(hidden = true)
	public Result<Page<SysMenuRes>> pageList(HttpServletRequest request, SysMenu sysMenu) {
		return Result.fail(REnum.USED_FORBIDDEN);
	}

	@Override
	public <E extends SysMenuReq> Result<A> save(HttpServletRequest request, @RequestBody @Valid E e) {
		sysMenuService.save(request, e, SysMenu.class);
		return Result.success();
	}

	@Override
	public <E extends SysMenuReq> Result<A> update(HttpServletRequest request, @RequestBody @Valid E e) {
		sysMenuService.update(request, e, SysMenu.class);
		return Result.success();
	}

	@GetMapping("/selectTree")
	@Operation(summary = "查询菜单树")
	public Result<SysMenuRes> selectMenuTree(){
		SysMenuRes res = sysMenuService.selectTree();
		return Result.success(res);
	}
}
